<?php

namespace app\common\library\supply\engine;

use think\facade\Request;
use think\Exception;

/**
 * 供应商抽象类
 */
abstract class Server
{
    protected $error;

    /**
     * 构造函数
     */
    protected function __construct()
    {
    }

    /**
     * 直冲
     */
    abstract protected function justRecharge();

    /**
     * 请求数据
     */
    abstract protected function sendData($param);

    /**
     * 返回错误信息
     */
    public function getError()
    {
        return $this->error;
    }

    protected function post($url, $data = [], $header = [])
    {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_POST, TRUE);
        curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
        $result = curl_exec($curl);
        curl_close($curl);
        return $result;
    }

}
